/*=============================================================================

  MAINFRAME APPLICATION DEFINITION

  FILE: MainFrm_app.c
  
  DESCRIPTION

    Application Process Implementation

  EXTERNALIZED FUNCTIONS


   Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

  EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when       who       what, where, why
  ---------  -------  -------------------------------------------------------
   08/14/04   nso4th    Initial version

=============================================================================*/

/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include <mainFrm.h>

/*=============================================================================
  CONSTANT INCLUSION
=============================================================================*/

/*=============================================================================
  EXTERNALIZED FUNCION DEFINITION
=============================================================================*/
void CMainFrame::appInit(void)
{
	EnableWindow(FALSE);
	LOGINIT(0);
	SYSLOG_INIT();

#ifndef TG_UI_NO_SPLASH
{
	//static char		szVer[128];

	//UIprm_Get(UI_VERSION_SP, (dword)szVer, 128);
	//GSplash::SetVersion(450, 350, GC_GRAY, szVer);
	GSplash::StartScreen(BMP_SPLASH, this);
}
#endif
	
	// Register the window message
	EHandler_Init(m_hWnd, CUST_UI_MSG);

	// UI manager
	if(m_mgrUI == NULL)
	{
		m_mgrUI = new UImgr;
	}
	m_mgrUI->Init();

	// Application manager
	if(m_mgrApp == NULL)
	{
		m_mgrApp = new SYSmgr;
	}
	m_mgrApp->Event_SetRecv(m_mgrUI);
	m_mgrApp->Init();
	
	// Request the UI initialization
	m_mgrUI->REQ_appInit();

#ifndef TG_UI_NO_SPLASH
	Task_Delay(2000);
	GSplash::StopScreen();
#endif
}

void CMainFrame::appInitDone(void)
{
	EnableWindow(TRUE);
}

void CMainFrame::appClose(void)
{
	EnableWindow(FALSE);

	SYSLOG_CLOSE();
	LOGCLOSE();

#ifndef TG_UI_NO_SPLASH
{
	//static char		szVer[128];

	//UIprm_Get(UI_VERSION_SP, (dword)szVer, 128);
	//GSplash::SetVersion(450/*400*/, 350, GC_GRAY, szVer);
	GSplash::StartScreen(BMP_SPLASH, this);
}
#endif
	
	if(m_mgrUI == NULL)
	{
		PostMessage(WM_CLOSE, 0, 0);
		return;
	}
	m_mgrUI->REQ_appClose();
}

void CMainFrame::appCloseDone(void)
{
	// Application manager
	if(m_mgrApp)
	{
		delete m_mgrApp;
		m_mgrApp = NULL;
	}
	
	// UI manager
	if(m_mgrUI)
	{
		m_mgrUI->Close();
		delete m_mgrUI;
		m_mgrUI = NULL;
	}

	// Deregister the window message
	EHandler_Close();

#ifndef TG_UI_NO_SPLASH
	Task_Delay(500);
	GSplash::StopScreen();
#endif
}

dword CMainFrame::appMSGHandler(dword type, dword event, dword wp, dword lp)
{
	DWORD		msg, msgID;

	msg = HDEV_GETEVENT(event);
	msgID = HDEV_GETDEV_ID(event);

	switch(type)
	{
	case UI_DEV:
	{
		switch(event)
		{
		case UI_NOTIREQ_E:
		{
			NBOX_DISP((mcxt)wp);
			return	(TRUE);
		}
		}
		break;
	}
	}

	return	m_vwMain.Event_Handler(type, event, wp, lp);
}

/*--- END OF MainFrm_app.cpp ---*/
